package com.wiloon.java8x.basic.jmx;

/*
 * Created by roy on 5/27/17;
 */

import java.lang.management.ManagementFactory;
import java.util.concurrent.TimeUnit;
import javax.management.MBeanServer;
import javax.management.ObjectName;


public class App {
    public static void main(String[] args) throws Exception {
        // 创建MBeanServer
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

        // 新建MBean ObjectName, 在MBeanServer里标识注册的MBean
        ObjectName name = new ObjectName("com.wiloon.java8x.basic.jmx:type=Echo");

        // 创建MBean
        Echo mbean = new Echo();

        // 在MBeanServer里注册MBean, 标识为ObjectName(com.wiloon.java8x.basic.jmx:type=Echo)
        mbs.registerMBean(mbean, name);

        // 在MBeanServer里调用已注册的EchoMBean的print方法
        mbs.invoke(name, "print", new Object[]{"jmx"}, new String[]{"java.lang.String"});

        //Thread.sleep(Long.MAX_VALUE);
        TimeUnit.SECONDS.sleep(Long.MAX_VALUE);
    }
}